﻿// =================================================================== 
// 项目说明
//====================================================================
// Wup。@Copy Right 2014
// 文件： YearMeeting.cs
// 项目名称：买车网
// 创建时间：2015/12/17
// 负责人：Wup
// ===================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Weixin.Entity.ChinaTax;
using Weixin.Utils;


namespace Weixin.DAL.ChinaTax
{
    /// <summary>
    /// 数据层实例化接口类 dbo.YearMeeting.
    /// </summary>
    public partial class YearMeetingDataAccessLayer 
    {
		#region 构造函数


		/// <summary>
		/// 
		/// </summary>
		public YearMeetingDataAccessLayer()
		{
		}
		#endregion

        #region -----------实例化接口函数-----------
		
		#region 添加更新删除
		/// <summary>
		/// 向数据库中插入一条新记录。
		/// </summary>
		/// <param name="_YearMeetingModel">YearMeeting实体</param>
		/// <returns>新插入记录的编号</returns>
		public int Insert(YearMeetingEntity _YearMeetingModel)
		{
			string sqlStr="insert into YearMeeting([Name],[Mobile],[Email],[Company],[WeiXin],[MeetingDate],[Remark],[CreateTime],[Status]) values(@Name,@Mobile,@Email,@Company,@WeiXin,@MeetingDate,@Remark,@CreateTime,@Status) select @@identity";
			int res;
			SqlParameter[] _param={
			new SqlParameter("@Name",SqlDbType.VarChar),
			new SqlParameter("@Mobile",SqlDbType.VarChar),
			new SqlParameter("@Email",SqlDbType.VarChar),
			new SqlParameter("@Company",SqlDbType.VarChar),
			new SqlParameter("@WeiXin",SqlDbType.VarChar),
			new SqlParameter("@MeetingDate",SqlDbType.VarChar),
			new SqlParameter("@Remark",SqlDbType.VarChar),
			new SqlParameter("@CreateTime",SqlDbType.DateTime),
			new SqlParameter("@Status",SqlDbType.Int)
			};			
			_param[0].Value=_YearMeetingModel.Name;
			_param[1].Value=_YearMeetingModel.Mobile;
			_param[2].Value=_YearMeetingModel.Email;
			_param[3].Value=_YearMeetingModel.Company;
			_param[4].Value=_YearMeetingModel.WeiXin;
			_param[5].Value=_YearMeetingModel.MeetingDate;
			_param[6].Value=_YearMeetingModel.Remark;
			_param[7].Value=_YearMeetingModel.CreateTime;
			_param[8].Value=_YearMeetingModel.Status;
			res = Convert.ToInt32(SqlHelper.ExecuteScalar(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param));
			return res;
		}
		/// <summary>
		/// 向数据库中插入一条新记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_YearMeetingModel">YearMeeting实体</param>
		/// <returns>新插入记录的编号</returns>
		public int Insert(SqlTransaction sp,YearMeetingEntity _YearMeetingModel)
		{
			string sqlStr="insert into YearMeeting([Name],[Mobile],[Email],[Company],[WeiXin],[MeetingDate],[Remark],[CreateTime],[Status]) values(@Name,@Mobile,@Email,@Company,@WeiXin,@MeetingDate,@Remark,@CreateTime,@Status) select @@identity";
			int res;
			SqlParameter[] _param={
			new SqlParameter("@Name",SqlDbType.VarChar),
			new SqlParameter("@Mobile",SqlDbType.VarChar),
			new SqlParameter("@Email",SqlDbType.VarChar),
			new SqlParameter("@Company",SqlDbType.VarChar),
			new SqlParameter("@WeiXin",SqlDbType.VarChar),
			new SqlParameter("@MeetingDate",SqlDbType.VarChar),
			new SqlParameter("@Remark",SqlDbType.VarChar),
			new SqlParameter("@CreateTime",SqlDbType.DateTime),
			new SqlParameter("@Status",SqlDbType.Int)
			};			
			_param[0].Value=_YearMeetingModel.Name;
			_param[1].Value=_YearMeetingModel.Mobile;
			_param[2].Value=_YearMeetingModel.Email;
			_param[3].Value=_YearMeetingModel.Company;
			_param[4].Value=_YearMeetingModel.WeiXin;
			_param[5].Value=_YearMeetingModel.MeetingDate;
			_param[6].Value=_YearMeetingModel.Remark;
			_param[7].Value=_YearMeetingModel.CreateTime;
			_param[8].Value=_YearMeetingModel.Status;
			res = Convert.ToInt32(SqlHelper.ExecuteScalar(sp,CommandType.Text,sqlStr,_param));
			return res;
		}


		/// <summary>
		/// 向数据表YearMeeting更新一条记录。
		/// </summary>
		/// <param name="_YearMeetingModel">_YearMeetingModel</param>
		/// <returns>影响的行数</returns>
		public int Update(YearMeetingEntity _YearMeetingModel)
		{
            string sqlStr="update YearMeeting set [Name]=@Name,[Mobile]=@Mobile,[Email]=@Email,[Company]=@Company,[WeiXin]=@WeiXin,[MeetingDate]=@MeetingDate,[Remark]=@Remark,[CreateTime]=@CreateTime,[Status]=@Status where ID=@ID";
			SqlParameter[] _param={				
				new SqlParameter("@ID",SqlDbType.Int),
				new SqlParameter("@Name",SqlDbType.VarChar),
				new SqlParameter("@Mobile",SqlDbType.VarChar),
				new SqlParameter("@Email",SqlDbType.VarChar),
				new SqlParameter("@Company",SqlDbType.VarChar),
				new SqlParameter("@WeiXin",SqlDbType.VarChar),
				new SqlParameter("@MeetingDate",SqlDbType.VarChar),
				new SqlParameter("@Remark",SqlDbType.VarChar),
				new SqlParameter("@CreateTime",SqlDbType.DateTime),
				new SqlParameter("@Status",SqlDbType.Int)
				};				
				_param[0].Value=_YearMeetingModel.ID;
				_param[1].Value=_YearMeetingModel.Name;
				_param[2].Value=_YearMeetingModel.Mobile;
				_param[3].Value=_YearMeetingModel.Email;
				_param[4].Value=_YearMeetingModel.Company;
				_param[5].Value=_YearMeetingModel.WeiXin;
				_param[6].Value=_YearMeetingModel.MeetingDate;
				_param[7].Value=_YearMeetingModel.Remark;
				_param[8].Value=_YearMeetingModel.CreateTime;
				_param[9].Value=_YearMeetingModel.Status;
			return SqlHelper.ExecuteNonQuery(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param);
		}
		/// <summary>
		/// 向数据表YearMeeting更新一条记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_YearMeetingModel">_YearMeetingModel</param>
		/// <returns>影响的行数</returns>
		public int Update(SqlTransaction sp,YearMeetingEntity _YearMeetingModel)
		{
            string sqlStr="update YearMeeting set [Name]=@Name,[Mobile]=@Mobile,[Email]=@Email,[Company]=@Company,[WeiXin]=@WeiXin,[MeetingDate]=@MeetingDate,[Remark]=@Remark,[CreateTime]=@CreateTime,[Status]=@Status where ID=@ID";
			SqlParameter[] _param={				
				new SqlParameter("@ID",SqlDbType.Int),
				new SqlParameter("@Name",SqlDbType.VarChar),
				new SqlParameter("@Mobile",SqlDbType.VarChar),
				new SqlParameter("@Email",SqlDbType.VarChar),
				new SqlParameter("@Company",SqlDbType.VarChar),
				new SqlParameter("@WeiXin",SqlDbType.VarChar),
				new SqlParameter("@MeetingDate",SqlDbType.VarChar),
				new SqlParameter("@Remark",SqlDbType.VarChar),
				new SqlParameter("@CreateTime",SqlDbType.DateTime),
				new SqlParameter("@Status",SqlDbType.Int)
				};				
				_param[0].Value=_YearMeetingModel.ID;
				_param[1].Value=_YearMeetingModel.Name;
				_param[2].Value=_YearMeetingModel.Mobile;
				_param[3].Value=_YearMeetingModel.Email;
				_param[4].Value=_YearMeetingModel.Company;
				_param[5].Value=_YearMeetingModel.WeiXin;
				_param[6].Value=_YearMeetingModel.MeetingDate;
				_param[7].Value=_YearMeetingModel.Remark;
				_param[8].Value=_YearMeetingModel.CreateTime;
				_param[9].Value=_YearMeetingModel.Status;
			return SqlHelper.ExecuteNonQuery(sp,CommandType.Text,sqlStr,_param);
		}		
		
		
		/// <summary>
		/// 删除数据表YearMeeting中的一条记录
		/// </summary>
	    /// <param name="ID">iD</param>
		/// <returns>影响的行数</returns>
		public int Delete(int ID)
		{
			string sqlStr="delete from YearMeeting where [ID]=@ID";
			SqlParameter[] _param={			
			new SqlParameter("@ID",SqlDbType.Int),
			
			};			
			_param[0].Value=ID;
			return SqlHelper.ExecuteNonQuery(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param);
		}
		
		/// <summary>
		/// 删除数据表YearMeeting中的一条记录,带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
	    /// <param name="ID">iD</param>
		/// <returns>影响的行数</returns>
		public int Delete(SqlTransaction sp,int ID)
		{
			string sqlStr="delete from YearMeeting where [ID]=@ID";
			SqlParameter[] _param={			
			new SqlParameter("@ID",SqlDbType.Int),
			
			};			
			_param[0].Value=ID;
			return SqlHelper.ExecuteNonQuery(sp,CommandType.Text,sqlStr,_param);
		}
		#endregion
		
		#region 数据实体
		/// <summary>
		/// 得到  yearmeeting 数据实体
		/// </summary>
		/// <param name="row">row</param>
		/// <returns>yearmeeting 数据实体</returns>
		public YearMeetingEntity Populate_YearMeetingEntity_FromDr(DataRow row)
		{
			YearMeetingEntity Obj = new YearMeetingEntity();
			if(row!=null)
			{
				Obj.ID = (( row["ID"])==DBNull.Value)?0:Convert.ToInt32( row["ID"]);
				Obj.Name =  row["Name"].ToString();
				Obj.Mobile =  row["Mobile"].ToString();
				Obj.Email =  row["Email"].ToString();
				Obj.Company =  row["Company"].ToString();
				Obj.WeiXin =  row["WeiXin"].ToString();
				Obj.MeetingDate =  row["MeetingDate"].ToString();
				Obj.Remark =  row["Remark"].ToString();
				Obj.CreateTime = (( row["CreateTime"])==DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime( row["CreateTime"]);
				Obj.Status = (( row["Status"])==DBNull.Value)?0:Convert.ToInt32( row["Status"]);
			}
			else
			{
				return null;
			}
			return Obj;
		}
		
        /// <summary>
		/// 得到  yearmeeting 数据实体
		/// </summary>
		/// <param name="dr">dr</param>
		/// <returns>yearmeeting 数据实体</returns>
		public YearMeetingEntity Populate_YearMeetingEntity_FromDr(IDataReader dr)
		{
			YearMeetingEntity Obj = new YearMeetingEntity();
			
				Obj.ID = (( dr["ID"])==DBNull.Value)?0:Convert.ToInt32( dr["ID"]);
				Obj.Name =  dr["Name"].ToString();
				Obj.Mobile =  dr["Mobile"].ToString();
				Obj.Email =  dr["Email"].ToString();
				Obj.Company =  dr["Company"].ToString();
				Obj.WeiXin =  dr["WeiXin"].ToString();
				Obj.MeetingDate =  dr["MeetingDate"].ToString();
				Obj.Remark =  dr["Remark"].ToString();
				Obj.CreateTime = (( dr["CreateTime"])==DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime( dr["CreateTime"]);
				Obj.Status = (( dr["Status"])==DBNull.Value)?0:Convert.ToInt32( dr["Status"]);
			
			return Obj;
		}
		#endregion
		
		/// <summary>
		/// 根据ID,返回一个YearMeeting对象
		/// </summary>
		/// <param name="iD">iD</param>
		/// <returns>YearMeeting对象</returns>
		public YearMeetingEntity Get_YearMeetingEntity (int iD)
		{
			YearMeetingEntity _obj=null;
			SqlParameter[] _param={
			new SqlParameter("@ID",SqlDbType.Int)
			};
			_param[0].Value=iD;
			string sqlStr="select * from YearMeeting with(nolock) where ID=@ID";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param))
			{
				while(dr.Read())
				{
            		_obj=Populate_YearMeetingEntity_FromDr(dr);
				}
			}
			return _obj;
		}
		/// <summary>
		/// 得到数据表YearMeeting所有记录
		/// </summary>
		/// <returns>数据集</returns>
		public IList< YearMeetingEntity> Get_YearMeetingAll()
		{
			IList< YearMeetingEntity> Obj=new List< YearMeetingEntity>();
			string sqlStr="select * from YearMeeting";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(WebConfig.ChinaTax,CommandType.Text,sqlStr))
			{
				while(dr.Read())
				{
					Obj.Add(Populate_YearMeetingEntity_FromDr(dr));
				}
			}
			return Obj;
		}
		/// <summary>
        /// 检测是否存在根据主键
        /// </summary>
        /// <param name="iD">iD</param>
        /// <returns>是/否</returns>
		public bool IsExistYearMeeting(int iD)
		{
			SqlParameter[] _param={
                                      new SqlParameter("@iD",SqlDbType.Int)
                                  };
            _param[0].Value=iD;
            string sqlStr="select Count(*) from YearMeeting where ID=@iD";
            int a=Convert.ToInt32(SqlHelper.ExecuteScalar(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param));
            if(a>0)
            {
                return true;
            }
            else
            {
                return false;
            }
		}

        #endregion
		
		#region----------自定义实例化接口函数----------
		#endregion
    }
}
